// wcbts.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "wcbts.h"
#include <windows.h>
#include <commctrl.h>
#include "WidcommStack.h"

HMODULE g_hModule = NULL;

/*
* Main function
*/
BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}

/*
* Check Widcom stack present
*/
WCBTS_API BOOL WidcommStackPresent()
{
	HMODULE hModule;

	hModule = LoadLibrary(L"BtSdkCE30.dll");
	if(hModule != NULL)
	{
		FreeLibrary(hModule);
		return 3;
	}

	hModule = LoadLibrary(L"BtSdkCE50.dll");
	if(hModule != NULL)
	{
		FreeLibrary(hModule);
		return 5;
	}

	return 0;
}

/*
* Create stack
*/
WCBTS_API void* CreateStack()
{
	if(g_hModule == NULL)
		g_hModule = LoadLibrary(L"wcbts.dll");

	return new CWidcommStack();
}

/*
* Delete stack
*/
WCBTS_API void DeleteStack(void *pStack)
{
	CWidcommStack*	pWcStack = (CWidcommStack*)pStack;
	if(pWcStack)
		delete pWcStack;

	if(g_hModule != NULL)
	{
		FreeLibrary(g_hModule);
		g_hModule = NULL;
	}
}
